#include "bsp/bsp.h"
#include "bsp/cpu_driver.h"

#ifdef CONFIG_CPU_TICK_TIMER
TIM_HandleTypeDef htim_ticks;

void cpu_ticks_timer_init(void){
	CPU_TICK_TIMER_CLK_ENABLE();

   	TIM_MasterConfigTypeDef sMasterConfig = {0};
   
   	htim_ticks.Instance = CONFIG_CPU_TICK_TIMER;
   	htim_ticks.Init.Prescaler = CPU_TICK_TIMER_CLKM - 1;
   	htim_ticks.Init.CounterMode = TIM_COUNTERMODE_UP;
   	htim_ticks.Init.Period = 0xFFFFFFFF; /* 支持32bit的timer，需要设置AAR超过16bit，否则计数器还是16bit模式 */
   	htim_ticks.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
   	HAL_TIM_Base_Init(&htim_ticks);
	__HAL_TIM_ENABLE(&htim_ticks);
	__HAL_TIM_SetCounter(&htim_ticks, 0xFFFFFFFF);
}
#endif
